package keeto.com.vn.classified.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.classified.core.ClassifiedCore;
import keeto.com.vn.classified.core.ClassifiedListener;
import keeto.com.vn.classified.network.IProtocol;
import keeto.com.vn.classified.request.LogoutRequest;
import keeto.com.vn.classified.response.LogoutResponse;

public class TaskLogout extends AbstractTask{
	String authKey;
	public TaskLogout(ClassifiedListener listener, ClassifiedCore core, String autheKey) {
		super(listener, core);
		// TODO Auto-generated constructor stub
		this.authKey=autheKey;;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		LogoutRequest request= new LogoutRequest();
		request.setAuthenKey(authKey);
		LogoutResponse response=json.finishLogout(request);
		for(ClassifiedListener mListener:listeners){
			mListener.finishLogoff(response.getReturnCode());
		}
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for(ClassifiedListener mListener:listeners){
			mListener.finishLogoff(IProtocol.STATUS_CODE_GENERICFAIL_500);
		}
	}

}
